package com.tjetc.controller;

import com.tjetc.domain.ChatHistory;
import com.tjetc.service.ChatHistoryService;
import com.tjetc.vo.ChatHistoryCategory;
import com.tjetc.vo.Result;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.Date;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/chatHistory")
public class ChatHistoryController {
    @Resource
    private ChatHistoryService chatHistoryService;



    
    @RequestMapping("/add")
    public Result add(@RequestBody ChatHistory chatHistory){
        chatHistory.setDate(new Date());
        return chatHistoryService.add(chatHistory);

    }
    @RequestMapping("del/{id}")
    public Result del(@PathVariable Integer id){
        return chatHistoryService.del(id);
    }
    @RequestMapping("/findAllChatHistoryById")
    public List<ChatHistory> findAllById(@RequestParam("senderId") Integer senderId,
                                         @RequestParam("receiveId") Integer receiveId) throws IOException {
        return chatHistoryService.findAllById(senderId,receiveId);

    }

    @RequestMapping("/findById")
    public List<ChatHistoryCategory>  findById(@RequestParam("userId")Integer userId) throws IOException {
        return chatHistoryService.chatHistoryCategoryList(userId);
    }
    @RequestMapping("/clearNoRead")
    public void clearNoRead(@RequestParam("userId")Integer userId,@RequestParam("receiverId")Integer receiverId){
        chatHistoryService.clearNoRead(userId,receiverId);
    }





    @RequestMapping("/test")
    public void test(){
        chatHistoryService.test();
    }

    @RequestMapping("/importAll")
    public boolean importAll() throws IOException {
        return chatHistoryService.importAll();
    }
    @RequestMapping("findAll")
    public void findAll() throws IOException {
         chatHistoryService.findAll();
    }





}
